﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FAS.App_Code;
using FAS.Objetos;

namespace FasGUI
{
    public partial class FormFiltroExamen : Form
    {
        private Form inicio;
        public FormFiltroExamen(Form inicio)
        {
            this.inicio = inicio;
            InitializeComponent();
            fillAll();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            fillAll();
        }

        private DataGridViewTextBoxCell getCell(String value)
        {
            DataGridViewTextBoxCell celda = new DataGridViewTextBoxCell();
            celda.Value = value;
            return celda;
        }

        public void fillAll()
        {
            this.dataGridView1.Rows.Clear();
            ConexionMySQL conexion = new ConexionMySQL();
            DataSet data = conexion.GetQuery("SELECT * FROM examen where Clave LIKE '%"+textBox1.Text+"%'");
            this.dataGridView1.Rows.Clear();
            foreach (DataRow rowD in data.Tables[0].Rows)
            {
                string Clave = rowD["Clave"].ToString();
                DataGridViewRow row = new DataGridViewRow();
                row.Cells.Add(getCell(Clave));
                DataGridViewLinkCell l = new DataGridViewLinkCell();
                l.Value = "Ver";
                row.Cells.Add(l);
                DataGridViewLinkCell l2 = new DataGridViewLinkCell();
                l2.Value = "Editar";
                row.Cells.Add(l2);
                this.dataGridView1.Rows.Add(row);
            }
            this.dataGridView1.Columns[0].AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.ColumnHeader;
            this.dataGridView1.Columns[0].AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
            this.dataGridView1.Columns[1].AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.ColumnHeader;
            this.dataGridView1.Columns[1].AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
            this.dataGridView1.Columns[2].AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.ColumnHeader;
            this.dataGridView1.Columns[2].AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
        }


        private void clickdgv(object sender, DataGridViewCellEventArgs e)
        {
            int row = dataGridView1.SelectedCells[0].RowIndex;
            List<Examen> lst = new List<Examen>();
            Examen examen = Examen.getExamen(this.dataGridView1.Rows[row].Cells[0].Value.ToString());
            if(e.ColumnIndex == 1)
            { //VER
                lst.Add(examen);
                Parcial parcial = new Parcial(examen.Parcial, Materia.GetNombreMateria(examen.idMateria), examen.Periodo, lst);
                WordCreator pdf = new WordCreator(lst, parcial);
            }
            else if (e.ColumnIndex == 2) //EDITAR
            {
                this.Hide();
                new EditarExamen(this, examen);
            }
        }

        private void FormFiltroCatalogo_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Dispose();
            inicio.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Dispose();
            inicio.Show();
        }

        private void textBox1_TextChanged_1(object sender, EventArgs e)
        {
            fillAll();
        }
    }
}